package pl.edu.agh.student.logic.webapp;

import java.util.HashMap;
import java.util.Map;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

@org.jboss.seam.annotations.faces.Converter
@Name("taskNameConverter")
@BypassInterceptors
public class TaskNameConverter implements Converter{

    private static Map<String, String> taskNamesMap;
    static{
    	taskNamesMap = new HashMap<String, String>();
    	
    	//Tasks:
    	taskNamesMap.put("filling form", "Wypełnianie wniosku");
    	taskNamesMap.put("checking form", "Sprawdzanie wniosku");
    	taskNamesMap.put("checking in BIK", "Sprawdzanie w BIK");
    	taskNamesMap.put("analysing", "Analiza wniosku");
    	taskNamesMap.put("deciding", "Końcowa decyzja");
    	
    	//End states:
    	taskNamesMap.put("cancel1", "Odrzucony przy sprawdzeniu");
    	taskNamesMap.put("analysis failed", "Odrzucony przy analizie lub BIKu");
    	taskNamesMap.put("end1", "Kredyt przyznany");
    }
	
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
    	System.out.println(taskNamesMap.containsKey(arg2) ? taskNamesMap.get(arg2) : "Błędna nazwa zadania");
    	return taskNamesMap.containsKey(arg2) ? taskNamesMap.get(arg2) : "Błędna nazwa zadania";
	}

	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
    	System.out.println(taskNamesMap.containsKey(arg2) ? taskNamesMap.get(arg2) : "Błędna nazwa zadania");
    	return taskNamesMap.containsKey(arg2) ? taskNamesMap.get(arg2) : "Błędna nazwa zadania";
	}

}
